package com.demo.netty;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

@Slf4j
public class JDKFutureDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建线程池
        ExecutorService service = Executors.newFixedThreadPool(2);
        //提交任务
        Future<Integer> future = service.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                log.info("future inside");
                return 20;
            }
        });
        log.info("wait result");
        //阻塞方法 等待结果
        Integer result = future.get();
        log.info("result:{}", result);
        //优雅关闭线程池
        service.shutdown();
    }

}
